For example, double quote marks typically indicate the
beginning and ending of a defined string literal. What if you
needed to include one or more double quotes in your string for
display? The following LScript code line would generate nothing
but errors:
You need to instruct LScript to ignore the quote marks within the
string as special characters, and this is accomplished by
escaping them:
Arrays can be created by several different methods. The first
method simply declares the array, indicating the number of
elements the array contains:
However, single-dimension (or "linear") arrays need not be explicitly
declared. LScript will allocate elements in a linear array "on-demand",
meaning that elements in an array will be created as they are accessed.
Multi-dimensional arrays, however, must still be explicitly declared
using the var keyword.
Linear arrays are created automatically by the LScript interpreter as
they are needed, or when the interpreter thinks they are needed.
In the case of functions that return multiple items, unless you tell
the interpreter explicitly how to handle the potential loss of data,
it will create an array to house the returning data to prevent the
destruction of returned data elements.
In the following example, the variabel 'firstItem' will be assigned
an array of three elements, containing the return values from the
parse() function:
numeric
Numeric values in LScript can be negative or positive, and can
include an optional decimal point to designate floating-point
values. LScript also supports scientific notation.
main
{
integer = 15;
real = 0.3;
negative = -35.356;
scientific = 7.5E+13;
...
}
string
String literals are represented by enclosing characters in
double quote marks at the beginning and end of the character
sequence:
main
{
astring = "Here is a test string";
...
}
As with C, LScript allows--and sometimes requires--you to "escape"
certain characters within your strings. Escaping a character
causes LScript to treat that character as a literal, as something
that is part of the string being defined and without special
meaning. To escape a character, use the back-slash character
(\) immediately before the character you wish LScript to process.
quoteString = ""I don't like this", he said";
LScript would interpret the first two double quote marks as
beginning and ending of the string literal you are assigning
to variable quoteString
, and then continue processing your
LScript starting with the first character in your intended
string. This is very bad.
quoteString = "\"I don't like this\", he said";
array
LScript supports arrays of up to ten (10) dimensions. Array
elements can hold any of the supported LScript data types (except
array; you cannot nest arrays). Each array can contain any mixture
of these data types.
main
{
var check[15];
...
}
Declaring an array in this fashion causes each element within
the new array to be marked internally as "uninitialized." You
cannot utilize an element in such a state until you have
assigned a value to it. LScript will detect any attempt to access
uninitialized array elements--or variables, for that matter--and
generate an error message.
...
firstItem = parse(" ","Hello there, everybody!");
...
You can explicitly override this automatic array creation behavior of
LScript's by employing an associative assignment of the returned
data:
... (firstItem) = parse(" ","Hello there, everybody!"); ...Once arrays are declared, individual elements can be accessed by referencing the array element directly. Array elements are accessed in LScript starting at offset one (1), as in Pascal, instead of zero (0), as in C or C++. Each LScript can use as many arrays as it needs, limited only by your computer's available memory.
Any expression that will evaluate to a integer value can be used as an array index. For example,
randElement = points[random(1,size(points))];Entire LScript arrays can also be initialized in a single step from a single value by assigning that value to the array using an empty index:
main { var check[15]; ... check[] = -1; // populate all 15 elements with '-1' ... }Because individual array elements are initialized to 'nil' as they are create by LScript, you can size an array and initialize all of its elements to 'nil' in one fell swoop:
main { ... check[15] = nil; // create the array, and initialize all elements ... }
main { apoint = <4.5,10,.03>; ... }Once declared, individual elements of the vector data type can be accessed using the keywords x, y, and z. For example:
main { apoint = <4.5,10,.03>; ++apoint.x; --apoint.y; if(apoint.x > 4) ... }
A good use of this value is in initializing or resetting arrays.
Initialization with this value avoids a potential run-time
error that can be generated when accessing uninitialized array
elements.
nil
nil can be both a condition and a data type in LScript. Variables
and array elements can be assigned--and tested for having--this
value. This value is also returned by certain LScript built-in
commands to indicate failure of some kind. For instance, the
object creation command File() will return nil if it cannot
create a File Object.
main
{
var check[15];
...
check[] = nil; // reset array values
...
}
You will probably want to initialize an array to nil when
dealing with LScript commands that have variable return values,
such as parse().process id
As with point id and polygon id, this data type is not
directly usable by an LScript. It is included in the LScript
data set to support the process control commands spawn(),
wait() and terminate().
Next Section
Previous Section
Table of Contents
Index
Errata
© 1996 Virtual Visions, Inc.
© 1997 NewTek, Inc.